# 创建SparkSession对象
from pyspark import SparkContext,SparkConf
from pyspark.sql import SparkSession
spark = SparkSession.builder.config(conf = SparkConf()).getOrCreate()

jdbcDF = spark.read.format("jdbc") \
    .option("driver","com.mysql.cj.jdbc.Driver") \
    .option("url", "jdbc:mysql://localhost:3306/spark?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8") \
    .option("dbtable", "student") \
    .option("user", "root") \
    .option("password", "root") \
    .load()
jdbcDF.show()
# /usr/lib/jvm/jdk1.8.0_162/bin: